FROM debian:9
MAINTAINER Xueqi <thucxq@gmail.com>

#  $ docker build . -t continuumio/anaconda3:latest -t continuumio/anaconda3:5.3.0
#  $ docker run --rm -it continuumio/anaconda3:latest /bin/bash
#  $ docker push continuumio/anaconda3:latest
#  $ docker push continuumio/anaconda3:5.3.0

ENV PYTHONUNBUFFERED 1

# Install Anaconda
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
ENV PATH /opt/conda/bin:$PATH

RUN apt-get update --fix-missing && apt-get install -y wget bzip2 ca-certificates \
    libglib2.0-0 libxext6 libsm6 libxrender1 \
    git mercurial subversion \
    vim nginx supervisor \
    curl grep sed dpkg \
    postgresql-client sqlite3\
	alien dpkg-dev debhelper build-essential libaio1 python3-pip && \
	rm -rf /var/lib/apt/lists/*

RUN wget --quiet https://repo.anaconda.com/archive/Anaconda3-5.3.0-Linux-x86_64.sh -O ~/anaconda.sh && \
    /bin/bash ~/anaconda.sh -b -p /opt/conda && \
    rm ~/anaconda.sh && \
    ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
    echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \
    echo "conda activate base" >> ~/.bashrc

# Install tini
ADD tini/tini_0.18.0.deb .
RUN dpkg -i tini_0.18.0.deb && \
    rm tini_0.18.0.deb && \
    apt-get clean

# install sklearn and sqlalchemy
RUN	conda update pip setuptools && \
	conda update -y scikit-learn && \
	conda install -c conda-forge uwsgi
RUN	pip install --upgrade pip && \
#	pip install uwsgi && \ # lto error when install uwsgi with Anaconda3-5.3(python3.6) use "conda install -c conda-forge uwsgi" instead
	pip install -U sqlalchemy==1.2.14

EXPOSE 8888 8080 8008 8000 80

# setup nginx and supervisor configfiles
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
COPY nginx-app.conf /etc/nginx/sites-available/default
COPY supervisor.conf /etc/supervisor/conf.d/


VOLUME /opt/notebooks
VOLUME /project
WORKDIR /build
ADD requirements.txt /build/
RUN pip install -r /build/requirements.txt \
	&& pip install git+git://github.com/sshwsfc/xadmin.git
ADD . /build/

# RUN django-admin.py startproject mysite /build/
# RUN /build/start.sh
WORKDIR /project

ENTRYPOINT [ "/usr/bin/tini", "--" ]
# CMD ["/bin/bash", "/build/start.sh"]
CMD ["supervisord", "-n"]
# CMD [ "/bin/bash" ]